package bocchi.power;

import bocchi.BocchiCore;
import bocchi.base.BaseCustomPower;
import bocchi.stance.HeroicStance;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageAllEnemiesAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.actions.watcher.ChangeStanceAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

public class ResolvePower extends BaseCustomPower {
    private static final String RAW_ID = "Resolve";
    public static final String GAME_ID = BocchiCore.getGameID(RAW_ID);

    public ResolvePower(AbstractCreature owner, int amount) {
        super(RAW_ID, PowerType.BUFF, owner, amount);
    }

    @Override
    public void updateDescription() {
        description = String.format(descriptions[0], amount * 2, amount * 2);
    }

    @Override
    public void atEndOfTurn(boolean isPlayer) {
        if (isPlayer) {
            flash();
            addToBot(new DamageAllEnemiesAction(AbstractDungeon.player, amount * 3, DamageInfo.DamageType.NORMAL, AbstractGameAction.AttackEffect.SMASH));
            addToBot(new GainBlockAction(owner, owner, amount * 3));
            addToBot(new ReducePowerAction(owner, owner, this, (amount + 1) / 2));
        }
    }

    @Override
    public void reducePower(int reduceAmount) {
        super.reducePower(reduceAmount);

        if (amount <= 0 && AbstractDungeon.player.stance.ID.equals(HeroicStance.GAME_ID)) {
            addToTop(new ChangeStanceAction("Neutral"));
        }
    }
}
